<template>
  <div class="risk">
    <!-- <van-search class="info_search" v-model="value" @search="onSearch" @clear="clearSearch" clearable placeholder="搜索" @cancel="onCancel" show-action action-text="清除" /> -->
    <van-list
      style="margin-top: 10px"
      :finished="finished"
      v-model="loading"
      finished-text="没有更多了"
    >
      <van-radio-group
        @change="handleChange"
        v-model="result"
      >
        <van-cell
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="risk_item_radio">
            <div>
              <div class="mb-10">{{ item.OrgName }}</div>
              <div>{{ item.OrgFullName }}</div>
            </div>
            <van-radio :name="item.OrgCode"></van-radio>
          </div>
        </van-cell>
      </van-radio-group>
    </van-list>
  </div>
</template>

<script>
import { getRiskDepartList } from "@/api/common";
import { getChooseOrgList } from "@/api/public";
export default {
  props: {
    SelectedValue: {
      type: String,
      required: false,
    },
    CompanyCode: {
      type: String,
      required: false,
    },
    IsPublic: {
      type: Boolean,
      required: false,
    },
  },
  data() {
    return {
      options: [],
      list: [],
      loading: false,
      finished: false,
      result: "",
      filter: {
        page: 0,
        showMyDept: false,
        onlyMyDept: false,
        accounted: true,
        orgType: "D",
        companyCode: "",
      },
      activeNames: ["1"],
      border: false,
      value: "",
      radio: "",
    };
  },
  created() {
    this.result = this.SelectedValue;
    this.filter.companyCode = this.CompanyCode;
    this.getList();
  },
  watch: {
    SelectedValue: {
      handler(newName, oldName) {
        this.result = newName;
      },
    },
  },
  methods: {
    handleChange(id) {
      const newData = this.list.filter((item) => item.OrgCode === id);
      if (newData.length > 0) {
        var item = {
          value: newData[0].OrgCode,
          name: newData[0].OrgName,
        };
        this.$emit("CallBack", item);
      }
    },
    onCancel() {
      var item = {
        value: "",
        name: "不限",
      };
      this.$emit("CallBack", item);
    },
    getList() {
      this.loading = true;
      if (this.IsPublic) {
        getChooseOrgList(this.filter)
          .then((res) => {
            this.loading = false;
            this.list = res.data;
            this.options = res.data;
            this.finished = true;
          })
          .catch((err) => {
            this.finished = true;
          });
      } else {
        getRiskDepartList(this.filter)
          .then((res) => {
            this.loading = false;
            this.list = res.data;
            this.options = res.data;
            this.finished = true;
            //this.filter.page = res.data.PageIndex;
          })
          .catch((err) => {
            this.finished = true;
          });
      }
    },

    // 文件页面
    goFile() {
      // this.$router.push('/CommonInfo/InfoDetail')
    },
    onSearch(val) {
      if (keyWord) {
        this.list = this.fuzzyQuery(this.options, keyWord, "OrgPostName");
      } else {
        this.list = this.options;
      }
    },
    clearSearch() {
      this.list = this.options;
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.risk_item_radio {
  width: 100%;
  padding: 10px 20px;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
